package com.qianxing.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.qianxing.mapper.TbNationLanguagePackMapper;
import com.qianxing.po.TbNationAreaLanguagePackPO;
import com.qianxing.po.TbNationLanguagePackPO;
import com.qianxing.service.TbNationAreaLanguagePackService;
import com.qianxing.mapper.TbNationAreaLanguagePackMapper;
import com.qianxing.vo.NationDataVO;
import com.qianxing.vo.RegionalDataVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.stream.Collectors;

/**
 * @author JasonLong
 * @description 针对表【tb_nation_area_language_pack(地区方言数据表)】的数据库操作Service实现
 * @createDate 2023-07-13 09:20:39
 */
@Service
public class TbNationAreaLanguagePackServiceImpl extends ServiceImpl<TbNationAreaLanguagePackMapper, TbNationAreaLanguagePackPO> implements TbNationAreaLanguagePackService {

    @Autowired
    private TbNationAreaLanguagePackMapper nationAreaLanguagePackMapper;

    /**
     * 通过地区标记获取对应地区的数据
     *
     * @param regionFlag
     * @return RegionalDataVO
     */
    @Override
    public List<RegionalDataVO> getRegionLanguagePack(String regionFlag) {
        QueryWrapper<TbNationAreaLanguagePackPO> queryWrapper = new QueryWrapper<>();
        queryWrapper.like("nation_area_flag", regionFlag).eq("deleted", 0);
        return getListData(queryWrapper);
    }

    @Override
    public List<RegionalDataVO> getRegionDataByKeyword(String keyword, String regionFlag) {
        QueryWrapper<TbNationAreaLanguagePackPO> queryWrapper = new QueryWrapper<>();
        queryWrapper.like("nation_area_translation", keyword).like("nation_area_flag", regionFlag).eq("deleted", 0);
        return getListData(queryWrapper);
    }

    @Override
    public List<RegionalDataVO> getAll() {
        return getListData(null);
    }

    public List<RegionalDataVO> getListData(QueryWrapper<TbNationAreaLanguagePackPO> wrapper) {
        List<RegionalDataVO> regionalDataVoList = nationAreaLanguagePackMapper.selectList(wrapper).stream().map(m -> {
            RegionalDataVO regionalDataVO = new RegionalDataVO();
            regionalDataVO.setNationAreaVoiceurl(m.getNationAreaVoiceurl());
            regionalDataVO.setNationAreaTranslation(m.getNationAreaTranslation());
            regionalDataVO.setIsplay(m.getIsplay());
            regionalDataVO.setRegionFlag(m.getNationAreaFlag());
            return regionalDataVO;
        }).collect(Collectors.toList());
        return regionalDataVoList;
    }
}




